// 异步钩子 -- 并发
class AsyncParallelHook {
    // args => ['name']
    constructor(args) {
      this.tasks = [];
    }
    tapAsync(name, task) {
      this.tasks.push(task);
    }
    callAsync(...args) {
      let finalCallback = args.pop(); // 拿出最终的函数
      let index = 0;
      let done = () => {
        index++;
        if (index === this.tasks.length) {
          finalCallback();
        }
      };
      this.tasks.forEach((task) => {
        task(...args, done);
      });
    }
  }
  
  let hook = new AsyncParallelHook(["name"]);
  
  hook.tapAsync("node", (data, callback) => {
    setTimeout(() => {
      console.log("前端小溪(" + data + ") --- 学习node");
      callback();
    }, 2000);
  });
  hook.tapAsync("react", (data, callback) => {
    setTimeout(() => {
      console.log("前端小溪(" + data + ") --- 学习react");
      callback();
    }, 1000);
  });
  
  hook.callAsync("xiaoxi", () => {
    console.log("结束");
  });